<?
//---------------------------------------------
// AskTwitter - Twitter based realtime QA system
// Author: Seokchan (Channy) Yun
// License: BSD License
// Version: 0.1
//----------------------------------------------

	include "asklift.inc";

	// Setting up JSON and Twitter Library
	$json = new Services_JSON();
	$twitter = new Twitter($id, $pw);

	// finding lastid
	$lastid = _db_select_s("SELECT tid FROM followers ORDER BY id DESC limit 1");
	// finding new questions since lastid
        $output = $twitter->getFollowers("json");
       	$res = $json->decode($output);

	//print_r($res);
	$i=0;$sync=array();

	foreach($res as $value) {
	// Checking voting number or not?
	    if($value->id!= $lastid) { 
		$sync[$i]="INSERT INTO followers VALUES('',".$value->id.")";
		$twitter->createFriendship("json",$value->id);
		$i++;
	    }
	}

	// insert voting to database 
	for($j=1;$j<=$i;$j++) {
		//echo $sync[$i-$j];
		_db_insert($sync[$i-$j]);
	}
?>
